<template>
  <div class="list_container">
    <div class="opear_box">
      <el-form ref="form" label-width="80px" inline>
        <el-form-item label="工程名称">
          <el-input v-model="param.title" style="width:250px;"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="getAllList">查询</el-button>
          <el-button type="primary" icon="el-icon-search" @click="addProject">新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="list_table">
      <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        row-key="id"
        border
        default-expand-all
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      >
        <el-table-column type="index" width="50" label="#"></el-table-column>
        <el-table-column prop="title" label="工程名称" width="180"></el-table-column>
        <el-table-column prop="money" label="工程金额" width="150"></el-table-column>
        <el-table-column prop="address" label="工程地址" width="200"></el-table-column>
        <el-table-column prop="sjfa_title" label="设计方案" width="200"></el-table-column>
        <el-table-column prop="ysbz_title" label="验收标准" width="200"></el-table-column>
        <el-table-column prop="zrs_title" label="责任书" width="200"></el-table-column>
        <el-table-column prop="title" label="合同" width="200"></el-table-column>
        <el-table-column prop="create_time" label="创建日期" width="200"></el-table-column>
        <el-table-column label="操作" width="150">
          <template slot-scope="scope">
            <el-button size="mini">删除</el-button>
            <el-button size="mini" type="danger" @click="handleShow(scope.$index, scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div>
      <el-pagination
        style=" text-align: right;"
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="currentPage"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="param.page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="1000"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getProjectList } from "@/api/project";
export default {
  data() {
    return {
      currentPage: 1,
      //表数据
      tableData: [],
      // 查询参数
      param: {
        title: "",
        page: 1,
        page_size: 10,
      },
    };
  },
  created() {
    var that = this;
    that.getAllList();
  },
  mounted() {},
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      var that = this;
      that.param.page_size = val;
      that.getAllList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      var that = this;
      that.param.page = val;
      that.getAllList();
    },
    //获取项目列表
    async getAllList() {
      var that = this;
      const res = await getProjectList(that.param);
      console.log(res);
      if (res.data) {
        that.tableData = res.data;
      }
    },
    //查看工程详情
    handleShow(enevt1, event2) {
      console.log(event2);
      this.$router.push({
        path: "/project/info",
        query: { pageEvent: event2 },
      });
    },
    //新增项目
    addProject() {
      console.log("新增项目");
      this.$router.push({ path: "/project/add" });
    },
  },
};
</script>

<style scoped lang="scss">
.list_container {
}
.opear_box {
  padding: 15px;
  height: auto;
}
.list_table {
  padding: 15px;
}
</style>
